{include file="news/header.tpl"}
	<link href="./static/public/jsorder/css/order.css" rel="stylesheet" />

{literal}
<style>
.table th{background:#f0f0f0;}
.table td{text-align:left;}
.suoding{height:30px;}
.nj{width:60px;}
.num{width:60px;}
.ps{width:60px;}
.mj{width:60px;}
</style>
{/literal}

<!-- 头部// -->


	<!-- start: Content -->
			<div id="content" class="">
			
						
			<div class="row-fluid">


<div class="box"><!-- Default panel contents -->
<ul class="nav nav-tabs nav-stacked"> 
  <li><span class="badge badge-info pull-left" style="margin-top: 10px;">提示</span><a href="javascript:void(0)">  龙骨等配件无需购买，订单部会帮助你配对（但特价款扣板除外，特价款不含龙骨） 。尽可能的一次性添加所需产品，这样你的订单处理起来就更快。</a></li>
  <li><span class="badge badge-warning pull-left" style="margin-top: 10px;">注意</span><a href="javascript:void(0)">   如需配烤漆（金色）龙骨，需要在备注栏中备注。</a></li>
  <li><span class="badge badge-success pull-left" style="margin-top: 10px;">提示</span><a href="javascript:void(0)">  拍下订单后1小时内，可以电话取消订单 0573-82696190</a></li>

  <li><span class="badge badge-important pull-left" style="margin-top: 10px;">注意</span><a href="javascript:void(0)">  一天内订单额未满3000元不会审核</a></li>

</ul>


我的购物车
<table class="table  table-bordered table-hover " style="text-align:center;">
<tr class=""><th class="span3">产品名称</th><th class="span2">单价(元)</th><th class="span4">尺寸规格</th><th class="span2">一件数量</th><th class="span1">购买数量</th><th class="span2">操作</th></tr>
{if $goods!=""}
{foreach from=$goods item=l name=g}
{include file="buy/goods/{$l.module}.tpl"}
{/foreach}
{/if}
<tr>
<td>龙骨选择</td>
<td colspan="5">
<div class="form-inline">
<label class="radio">
<input type="radio" name="longgu" value="2.7米镀锌">2.7米镀锌
</label>
<label class="radio">
<input type="radio" name="longgu" value="4米镀锌" >4米镀锌
</label>
<label class="radio">
<input type="radio" name="longgu" value="2.7米烤漆">2.7米烤漆
</label>
<label class="radio">
<input type="radio" name="longgu" value="4米烤漆">4米烤漆
</label>
<label class="radio">
<input type="radio" name="longgu" value="不配龙骨">不配龙骨
</label>

</div>
</td>
</tr>
</table>

<a href="javascript:history.go(-1)" class="btn btn-warning">返回继续购物</a>

备注<input type="text" name="remark" class="input-xxlarge" value="" placeholder="如DIY定制画名称"> 
     <b>订单总金额：</b><span  id="totalcount" style="font-family:Verdana;color:red;font-size:16px;">{$totalcount}</span> 元 <a href="javascript:sub()" class="btn btn-danger pull-right">提交订单</a>
</div>
</div>


<div style="display:none">
<form action="/index.php?order/confirm" method="post" id="form">
<input  type="text" name="goodsinfo" id="goodsinfo">
</form>
</div>
<script type="text/javascript" src="./static/public/jsorder/js/cookie.js"></script>
<script type="text/javascript" src="./static/public/jsorder/js/jsorder.js"></script>
 <script  type="text/javascript" src="./static/public/layer/layer.min.js" ></script>
{literal}
<script type="text/javascript">
$(document).ready(function(){
   
 $(".nj").bind("change",nj);
 $(".ps").bind("change",ps);
 $(".mj").bind("change",mj);
 
})

function nj(){
	 var id=this.title;
	  var width=$("#njwidth"+id).val();
	  var length=$("#njlength"+id).val();
	 var module=$("#module"+id).val();
    var price=$("#unit"+id).val();
	  if(length>0&&width>0){
		  var price=(parseFloat(width)+parseFloat(length))*2*price;
			$("#price"+id).val(price);
			//存储
			var picture=module+"长为"+length+"m,宽为"+width+"m";
			snapshot(id,picture,price);
			 tj();
	  }
}

function ps(){
	 var id=this.title;
	  var width=$("#njwidth"+id).val();
	  var length=$("#njlength"+id).val();
	 var module=$("#module"+id).val();
  var price=$("#unit"+id).val();
	  if(length>0&&width>0){
		  var price=(parseFloat(width)*parseFloat(length))*price;
			$("#price"+id).val(price);
			//存储
			var picture=module+"高为"+length+"片,宽为"+width+"片";
			snapshot(id,picture,price);
			 tj();
	  }
}

function mj(){
	 var id=this.title;
	  var width=$("#njwidth"+id).val();
	  var length=$("#njlength"+id).val();
	 var module=$("#module"+id).val();
     var price=$("#unit"+id).val();
	  if(length>0&&width>0){
		  var price=(parseFloat(width)*parseFloat(length))*price;
			$("#price"+id).val(price);
			//存储
			var picture=module+"高为"+length+"m,宽为"+width+"m";
			snapshot(id,picture,price);
			 tj();
	  }
}

function checkempty(){
	   var a=$(".nj");
	   var b=(".ps");
	   var c=(".mj");
	   var flag=true;
	   
	   $(a).each(function(){
			if(this.value==""){
	          flag=false;
	          return false;
		    }
	  })
	  $(b).each(function(){
			if(this.value==""){
	          flag=false;
	          return false;
		    }
	  })
	   $(c).each(function(){
			if(this.value==""){
	          flag=false;
	          return false;
		    }
	  })
	return flag;
		
}

function sub(){
	
   if(checkempty()==false){
	 
		   layer.alert("请输入尺寸",8);
	     return;
	  
	  }
	
	var lg=$("input[name='longgu']:checked").val();
   if(lg==undefined){
     layer.alert("请选择龙骨",8);
     return;
   }
	
	
   if(!confirm("确认提交?")){
     return false;
	}

	var remark=$("input[name='remark']").val();
remark=remark+lg;
	$.post('./index.php?buyorder/add',{remark:remark},function(data){
     if(data.status==true){
       layer.alert(data.message,9,function(){
    	   window.parent.location.href="./index.php?buyorder/order";
           });
      
      }else{
      layer.alert(data.message,8);
       }
	},"json")
}

function mx(sku){
	$.layer({
	    type: 2,
	    shadeClose: true,
	    title: false,
	    closeBtn: [0, true],
	    shade: [0.3, '#000'],
	    border: [0],
	    offset: ['20px',''],
	    area: ['700px', ($(window).height() - 50) +'px'],
	    iframe: {src: './index.php?buy/mx/?sku='+sku,
	        scrolling: 'yes'
	      }
	}) 

}

function addCart(id){

	var h="<a href='javascript:void(0)' class='label label-warning'>已经添加</a>";
	$("#cart"+id).html(h);
}

//jsorder配置
$.fn.jsorder.defaults = {
	staticname : 'jsorder',
	jsorderclass : 'jsorder',
	savecookie : true,
	cookiename : 'buy',
	numpre : 'no_',
	jsorderpre : 'jsorder_',
	jsorderspanpre : 'jsorderspan_',
	pricefiled : 'price',
	namefiled : 'jsordername',
	leftdemo : '购物车',
	subbuttom : 'cart', 
	//addbuttom : 'a.jsorderadd', 
	addbuttom : 'a.jsorderadd', 
	nomessage : '你今天的包裹是还空的',
	dosubmit : function(data) {
$("#goodsinfo").val(JSON.stringify(data));
$("#form").submit();
}
};
$("body").jsorder();


function del(id){
	parseCookie(id);
	$("#s"+id).remove();
	tj(0);
}

function tj(id){
	
	var total=0;
	var i=0;
	var num=new Array();
	var leixing="";
	var prices=new Array();

	if(id!=0){
	if(event.which==8){	
        return;
    }
	}

	
	$('input').each(function(){

	if($(this).attr("class")!=leixing){
	leixing=$(this).attr("class");

	}

	
	

	if(leixing=="num"){
	if(!isNumber($(this).val())){
	$(this).val(1);
	alert("只能输入整数");

	return;
	}
	 num.push($(this).val());
	}

	if(leixing=="prices"){
	prices.push($(this).val());
	}
	});

	for(var j=0;j<num.length;j++){
	  total+=num[j]*prices[j];
	}
	$("#totalcount").html(total);

	var a=parseInt($("#goods_"+id).val());
	parseNum(id,a);

	}

	function isNumber( s )
	{
	    var regu = "^[0-9]+$";
	    var re = new RegExp(regu);
	    if (s.search(re) != - 1) {
	        return true;
	    }
	    else {
	        return false;
	    }
	}

	//初始化购物车
	function snapshot(id,snapshot,price){
		  var data=JSON.parse($.cookie("buy"));
         data[id]['snapshot']=snapshot;
         data[id]['price']=price;
		  $.cookie("buy", JSON.stringify(data), {
				path : '/',
				expires : 0
			});
		  }  
	  
	function  parseCookie(id){
	  var data=JSON.parse($.cookie("buy"));
	delete data[id];
	$.cookie("buy", JSON.stringify(data), {
	    					path : '/',
							expires : 0
						});

	}  

	function parseNum(id,num){
	    
	      var data=JSON.parse($.cookie("buy"));
	 data[id]['count']=num;
	$.cookie("buy", JSON.stringify(data), {
	        				path : '/',
							expires : 0
						});
	}

</script>
{/literal}

